package com.sq.universe.gateway.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.gateway.config.GatewayProperties;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/gateWay")
public class GateWayController {

    @Autowired
    private GatewayProperties gatewayProperties;


    @RequestMapping("/getGateWayConfig")
    public  Map getGateWayConfig(){
        Map config = new HashMap();
        for (int i = 0; i < gatewayProperties.getRoutes().size(); i++) {
            RouteDefinition routeDefinition = gatewayProperties.getRoutes().get(i);
            config.put(routeDefinition.getUri().toString().replace("lb://",""),routeDefinition.getPredicates().get(0).getArgs().get("_genkey_0").replace("/**",""));
        }
        return config;
    }
}
